home *** CD-ROM | disk | FTP | other *** search
/ Language/OS - Multiplatform Resource Library / LANGUAGE OS.iso / lisp / elk-2_0.lha / elk-2.0 / contrib / zelk / src-elk / stab.c < prev    next >
Encoding:
C/C++ Source or Header  |  1992-11-13  |  2.9 KB  |  135 lines

  1. /* Read and manage symbol tables from object modules
  2.  */
  3.  
  4. #include "scheme.h"
  5. #if ZELK
  6. # include <zelk.h>
  7. #endif
  8.  
  9. #if defined(CAN_LOAD_OBJ) || defined (INIT_OBJECTS)
  10.  
  11. #ifdef MACH_O
  12. #  include "stab.macho.c"
  13. #else
  14. #ifdef ELF
  15. #  include "stab.elf.c"
  16. #else
  17. #if defined(COFF) || defined(XCOFF)
  18. #  include "stab.coff.c"
  19. #else
  20. #ifdef ECOFF
  21. #  include "stab.ecoff.c"
  22. #else
  23. #if defined(hp9000s300) || defined(__hp9000s300__)
  24. #  include "stab.hp9k300.c"
  25. #else
  26. #if defined(hp9000s800) || defined(__hp9000s800__)
  27. #  include "stab.hp9k800.c"
  28. #else
  29. #  include "stab.bsd.c"
  30. #endif
  31. #endif
  32. #endif
  33. #endif
  34. #endif
  35. #endif
  36.  
  37. Free_Symbols (tab) SYMTAB *tab; {
  38.     register SYM *sp;
  39.  
  40.     for (sp = tab->first; sp; sp = sp->next) {
  41. #if defined(COFF) || defined(ECOFF)
  42.     free (sp->name);
  43. #endif
  44.     free ((char *)sp);
  45.     }
  46.     if (tab->strings)
  47.     free (tab->strings);
  48.     free ((char *)tab);
  49. }
  50.  
  51. static char *Ignore_Prefixes[] =  { "init__", "finit__",  0 };
  52. static char *Init_Prefixes[] =  { "init_",  "__sti__", "_STI",
  53.                   "_GLOBAL_$I$", 0 };
  54. static char *Finit_Prefixes[] = { "finit_", "__std__", "_STD",
  55.                   "_GLOBAL_$D$", 0 };
  56.  
  57. static FUNCT *Finalizers;
  58.  
  59. static void Call (l) unsigned long l; {
  60. #ifdef XCOFF
  61.     unsigned long vec[3];
  62.     extern main();
  63.  
  64.     bcopy ((char *)main, (char *)vec, sizeof vec);
  65.     vec[0] = l + (vec[0] & 0xF0000000);
  66.     ((void (*)())vec)();
  67. #else
  68.     ((void (*)())l)();
  69. #endif
  70. }
  71.  
  72. Call_Initializers (tab, addr) SYMTAB *tab; char *addr; {
  73.     register SYM *sp;
  74.     register char *p, **pp;
  75.     int got_one = 0;
  76.     FUNCT *fp;
  77.  
  78.     for (sp = tab->first; sp; sp = sp->next) {
  79.     if ((char *)sp->value < addr)
  80.         continue;
  81.     p = sp->name;
  82. #ifdef SYMS_BEGIN_WITH
  83.     if (*p == SYMS_BEGIN_WITH)
  84.         p++;
  85.     else
  86.         continue;
  87. #endif
  88.     for (pp = Ignore_Prefixes; *pp; pp++)
  89.         if (strncmp (p, *pp, strlen(*pp)) == 0)
  90.         goto next;
  91.     for (pp = Init_Prefixes; *pp; pp++) {
  92.         if (strncmp (p, *pp, strlen (*pp)) == 0) {
  93.         got_one = 1;
  94.         Call (sp->value);
  95.         }
  96.     }
  97.     for (pp = Finit_Prefixes; *pp; pp++) {
  98.         if (strncmp (p, *pp, strlen (*pp)) == 0) {
  99.         fp = (FUNCT *)Safe_Malloc (sizeof (*fp));
  100.         fp->func = (void (*)())sp->value;
  101.         fp->next = Finalizers;
  102.         Finalizers = fp;
  103.         }
  104.     }
  105.  
  106. #ifdef ZELK
  107. #       define FORLIB "PKGrtn_"
  108. #       define FORLEN 7
  109.         /* load foreign libraries */
  110.         if (strncmp(p,FORLIB,FORLEN)==0) {
  111.             PKG_type *pkgtab;
  112.             /*printf("got forlib symbol :%s:\n",p);*/
  113.             pkgtab = (PKG_type *) ( (char * (*)()) sp->value )();
  114.             Zforpkginit(p+FORLEN,pkgtab);
  115.             got_one = 1;
  116.         }
  117. #endif /*ZELK*/
  118.  
  119. next: ;
  120.     }
  121.     return got_one;
  122. }
  123.  
  124. /* Call the finialization functions in reverse order.  Make sure that
  125.  * calling exit() from a finalizer doesn't cause endless recursion.
  126.  */
  127. Call_Finalizers () {
  128.     while (Finalizers) {
  129.     FUNCT *fp = Finalizers;
  130.     Finalizers = fp->next;
  131.     Call ((unsigned long)fp->func);
  132.     }
  133. }
  134. #endif /* CAN_LOAD_OBJ || INIT_OBJECTS */
  135.